<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="../menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/comments.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/live-comments.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/baseComments.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div class="page-header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div class="page-content-wrapper">
				<div class="page-blocks">
					<xsl:call-template name="default-blocks-top" />
				</div>
	
				<div class="page-content">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		<h1>Прямой эфир</h1>
		
		<div id="comments_list" class="comments-list">
			<xsl:apply-templates select="object[@type='comment']" />
		</div>
		
		<xsl:apply-templates select="pages" mode="pages-navigation">
			<xsl:with-param name="href">
				<xsl:value-of select="$baseURI" />
				<xsl:text>/comments</xsl:text>
			</xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="object[@type='comment']">
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="userAvatar" select="property[@name='user_avatar']/value" />
		<xsl:param name="allowVote" select="@allow-vote" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<a name="comment{@id}" />
		<div class="item extended" id="comment_{@id}">
			<xsl:attribute name="style">
				<xsl:value-of select="concat ('margin-left: ', number(@comment-level) * 50, 'px')" />
			</xsl:attribute>
			
			<xsl:if test="property[@name='deleted']/value = 1">
				<xsl:attribute name="class">item deleted</xsl:attribute>
				<p>Комментарий удален</p>
			</xsl:if>
			
			<xsl:if test="property[@name='deleted']/value = 0">
				<div class="object-relation">
					<xsl:call-template name="comment-relation" />
				</div>
				
				<div class="avatar">
					<a href="{$baseURI}/user/{$userLogin}">
						<xsl:if test="$userAvatar = ''">
							<img src="{$baseURI}/images/default-user-avatar.png" alt="{$userLogin}" />
						</xsl:if>
						<xsl:if test="$userAvatar != ''">
							<img src="{$baseURI}/thumb_50_50{$userAvatar}" alt="{$userLogin}" />
						</xsl:if>
					</a>
				</div>
				
				<div class="body">
					<div class="header">
						<a class="username" href="{$baseURI}/user/{$userLogin}">
							<xsl:value-of select="$userLogin" />
						</a>
						
						<span class="date">
							<xsl:value-of select="property[@name='pubdate']/value" />
						</span>
					</div>
					
					<div class="content">
						<xsl:value-of select="property[@name='text']/value" disable-output-escaping="yes" />
					</div>
					
					<xsl:if test="$userGroup = 'guest'">
						<div class="controls">
							<a href="#comment{@id}">ссылка</a>
						</div>
					</xsl:if>
					<xsl:if test="$userGroup != 'guest'">
						<div class="controls">
							<a href="#comment{@id}">ссылка</a>
							<xsl:if test="$userGroup = 'admin' or $userGroup = 'moderator'">
								<a href="#" onclick="if (confirm ('Вы действительно хотите удалить этот комментарий?')) Comment.delete ({@id}); return false;">удалить</a>
							</xsl:if>
						</div>
						<div class="reply" style="display:none;" id="new_comment_{@id}" />
					</xsl:if>
				</div>
			</xsl:if>
		</div>
		
		<!--xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="userAvatar" select="property[@name='user_avatar']/value" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		<xsl:param name="object" select="document(concat('xobject://', @type-name, '/', property[@name='object_id']/value))/data/object" />
		
		<a name="comment{@id}" />
		<div class="comment_item">
			<div class="live_comment_relation">
				<xsl:choose>
					<xsl:when test="@type-name='article' or @type-name='link'">
						<xsl:if test="$object/property[@name='blog_id']/value = 0">
							<a class="category">
								<xsl:attribute name="href">
									<xsl:value-of select="$baseURI" />
									<xsl:text>/blogs/user/</xsl:text>
									<xsl:value-of select="$object/property[@name='user_login']/value" />
								</xsl:attribute>
								<xsl:text>&labelLiveBlogOfUser; </xsl:text>
								<xsl:value-of select="$object/property[@name='user_name']/value" />
							</a>
						</xsl:if>
						
						<xsl:if test="$object/property[@name='blog_id']/value != 0">
							<xsl:text>&labelLiveFromBlog; </xsl:text>
							<a class="category">
								<xsl:attribute name="href">
									<xsl:value-of select="$baseURI" />
									<xsl:text>/blog/</xsl:text>
									<xsl:value-of select="$object/property[@name='blog_alias']/value" />
								</xsl:attribute>
								<xsl:value-of select="$object/property[@name='blog_title']/value" />
							</a>
						</xsl:if>
						<xsl:text> / </xsl:text>
						<a class="object">
							<xsl:attribute name="href">
								<xsl:value-of select="$baseURI" />
								<xsl:text>/post/</xsl:text>
								<xsl:value-of select="concat(@type-name, '/', $object/@id)" />
							</xsl:attribute>
							<xsl:value-of select="$object/property[@name='title']/value" disable-output-escaping="yes" />
						</a>
						
						<span class="count">
							<xsl:value-of select="$object/property[@name='count_comments']/value" />
						</span>
					</xsl:when>
					
					<xsl:when test="@type-name='photo'">
						<xsl:text>&labelLiveFromPhoto; </xsl:text>
						<a class="category photoalbum">
							<xsl:attribute name="href">
								<xsl:value-of select="$baseURI" />
								<xsl:text>/photoalbum/</xsl:text>
								<xsl:value-of select="$object/property[@name='album_id']/value" />
							</xsl:attribute>
							<xsl:value-of select="$object/property[@name='album_title']/value" />
						</a>
						<xsl:text> / </xsl:text>
						<a class="object">
							<xsl:attribute name="href">
								<xsl:value-of select="$baseURI" />
								<xsl:text>/photo/</xsl:text>
								<xsl:value-of select="$object/@id" />
							</xsl:attribute>
							<xsl:value-of select="$object/property[@name='title']/value" disable-output-escaping="yes" />
						</a>
						
						<span class="count">
							<xsl:value-of select="$object/property[@name='count_comments']/value" />
						</span>
					</xsl:when>
				</xsl:choose>
			</div>
			
			<div id="comment_inner_{@id}" class="live_comment_inner">
				<xsl:if test="property[@name='deleted']/value = '1'">
					<div class="comment_deleted">&labelDeleted;</div>
				</xsl:if>
				
				<xsl:if test="property[@name='deleted']/value = '0'">
					<div class="comment_header">
						<div class="comment_rating">
							<div class="comment_rating_number">
								<xsl:if test="number ($rating) &gt; 0">
									<xsl:attribute name="class">comment_rating_number plus</xsl:attribute>
									<xsl:text>+</xsl:text>
								</xsl:if>
								<xsl:if test="number ($rating) &lt; 0">
									<xsl:attribute name="class">comment_rating_number minus</xsl:attribute>
								</xsl:if>
								<xsl:value-of select="$rating" />
							</div>
						</div>
						
						<div class="comment_userpic">
							<a href="{$baseURI}/user/{$userLogin}">
								<xsl:if test="$userAvatar = ''">
									<img src="{$baseURI}/images/default-avatar-small.png" alt="" />
								</xsl:if>
								<xsl:if test="$userAvatar != ''">
									<img src="{$baseURI}/thumb_24_24{$userAvatar}" alt="" />
								</xsl:if>
							</a>
						</div>
						
						<a class="username" href="{$baseURI}/user/{$userLogin}">
							<xsl:value-of select="property[@name='user_name']/value" />
						</a>
						<span class="date">
							<xsl:value-of select="property[@name='pubdate']/value" />
						</span>
						
						<a class="comment_anchor" href="#comment{@id}" title="&labelLink;">
							<xsl:attribute name="href">
								<xsl:value-of select="$baseURI" />
								<xsl:choose>
									<xsl:when test="@type-name='article' or @type-name='link'">
										<xsl:value-of select="concat('/post/', @type-name, '/', $object/@id, '#comment', @id)" />
									</xsl:when>
									
									<xsl:when test="@type-name='photo'">
										<xsl:value-of select="concat('/photo/', $object/@id, '#comment', @id)" />
									</xsl:when>
								</xsl:choose>
							</xsl:attribute>
							<img src="{$baseURI}/images/anchor.png" align="top" alt="" />
						</a>
						
						<xsl:if test="$userGroup = 'admin' or $userGroup = 'moderator'">
							<a class="comment_delete" href="javascript:void(0)" title="&labelToDelete;" onclick="if (confirm ('&labelDeleteConfirm;'))deleteComment ({@id});">
								<img src="{$baseURI}/images/delete-icon.png" align="top" alt="" />
							</a>
						</xsl:if>
						
					</div>
					<div class="comment_content">
						<xsl:value-of select="property[@name='text']/value" disable-output-escaping="yes" />
					</div>
				</xsl:if>
			</div>
		</div-->
	</xsl:template>
	
	<xsl:template name="comment-relation">
		<xsl:param name="object" select="document(concat('xobject://', @type-name, '/', property[@name='object_id']/value))/data/object" />
		
		<xsl:choose>
			<xsl:when test="@type-name='article' or @type-name='link'">
				<xsl:if test="$object/property[@name='blog_id']/value = 0">
					<a class="category">
						<xsl:attribute name="href">
							<xsl:value-of select="$baseURI" />
							<xsl:text>/blogs/user/</xsl:text>
							<xsl:value-of select="$object/property[@name='user_login']/value" />
						</xsl:attribute>
						<xsl:text>Блог им. </xsl:text>
						<xsl:value-of select="$object/property[@name='user_name']/value" />
					</a>
				</xsl:if>
				
				<xsl:if test="$object/property[@name='blog_id']/value != 0">
					<xsl:text>Блог </xsl:text>
					<a class="category">
						<xsl:attribute name="href">
							<xsl:value-of select="$baseURI" />
							<xsl:text>/blog/</xsl:text>
							<xsl:value-of select="$object/property[@name='blog_alias']/value" />
						</xsl:attribute>
						<xsl:value-of select="$object/property[@name='blog_title']/value" />
					</a>
				</xsl:if>
				<xsl:text> → </xsl:text>
				<a class="object">
					<xsl:attribute name="href">
						<xsl:value-of select="$baseURI" />
						<xsl:text>/post/</xsl:text>
						<xsl:value-of select="concat(@type-name, '/', $object/@id)" />
					</xsl:attribute>
					<xsl:value-of select="$object/property[@name='title']/value" disable-output-escaping="yes" />
				</a>
				
				<span class="count">
					<xsl:value-of select="$object/property[@name='count_comments']/value" />
				</span>
			</xsl:when>
			
			<xsl:when test="@type-name='photo'">
				<xsl:text>Фото </xsl:text>
				<a class="category photoalbum">
					<xsl:attribute name="href">
						<xsl:value-of select="$baseURI" />
						<xsl:text>/photoalbum/</xsl:text>
						<xsl:value-of select="$object/property[@name='album_id']/value" />
					</xsl:attribute>
					<xsl:value-of select="$object/property[@name='album_title']/value" />
				</a>
				<xsl:text> → </xsl:text>
				<a class="object">
					<xsl:attribute name="href">
						<xsl:value-of select="$baseURI" />
						<xsl:text>/photo/</xsl:text>
						<xsl:value-of select="$object/@id" />
					</xsl:attribute>
					<xsl:value-of select="$object/property[@name='title']/value" disable-output-escaping="yes" />
				</a>
				
				<span class="count">
					<xsl:value-of select="$object/property[@name='count_comments']/value" />
				</span>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
</xsl:stylesheet>